package nl.weeaboo.sh.objects;

import javax.media.opengl.GL;

import nl.weeaboo.game.gl.GLImage;
import nl.weeaboo.game.gl.GLManager;
import nl.weeaboo.game.input.UserInput;
import nl.weeaboo.sh.Game;
import nl.weeaboo.sh.level.Level;

public class HitFlash extends Effect {

	private GLImage image;
	private int x, y;
	private double rotation;
	
	private int frame;
	private int maxFrame = 7;
	
	public HitFlash(Game game, Level level, int x, int y, double rotation) {
		super(game, level);
		
		this.image = game.getImage("object/impact.png#hitFlash", false);
		this.x = x;
		this.y = y;
		this.rotation = rotation;
	}
	
	//Functions	
	public void update(UserInput input, float dt) {
		frame++;
		if (frame > maxFrame) destroy();
	}
	public void drawBackground(GLManager glm) {		
	}
	public void drawForeground(GLManager glm) {
		GL gl = glm.getGL();
		gl.glPushMatrix();
		glm.pushColor();
		
		gl.glTranslated(x, y, 0);		
		gl.glRotated(rotation, 0, 0, -1);
		
		float c;
		if (frame <= 3) {
			c = frame / 3f;
		} else {
			c = 1.0f - (frame - 3) / 7f;
		}
		
		float scale = frame / 7f;
		glm.scale(scale, scale);
		
		glm.setColor(1, 1, 1, c);
		
		gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
		image.draw(glm, -image.getWidth()/2, -image.getHeight()/2);
		gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
		
		glm.popColor();
		gl.glPopMatrix();
	}

	//Getters
	
	//Setters
	
}
